package cn.vendmember.com.controller;

import cn.vendmember.com.mapper.UserESMapper;
import cn.vendmember.com.entity.User;
import org.dromara.easyes.core.conditions.select.LambdaEsQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * 用户ES控制器
 * @author Eleven
 */
@RestController
@RequestMapping("/user")
public class UserESController {

    @Autowired
    private UserESMapper userMapper;

    @GetMapping("/createIndex")
    public Boolean createIndex() {
        // 1.初始化-> 创建索引(相当于mysql中的表)
        return userMapper.createIndex();
    }

    @GetMapping("/insert")
    public Integer insert() {
        // 2.初始化-> 新增数据
        User user = new User();
        user.setUsername("老汉");
        user.setPhone("13800000000");
        user.setTitle("医生");
        user.setAddress("北京");
        return userMapper.insert(user);
    }

    @GetMapping("/search")
    public List<User> search() {
        LambdaEsQueryWrapper<User> wapper = new LambdaEsQueryWrapper<>();
        wapper.eq(User::getTitle, "医生");
        return userMapper.selectList(wapper);
    }
}
